﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace Smith.ImageConverter
{
    public partial class AdvanceForm : Form
    {
        public AdvanceForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// fire when form is loaded, to initialize settings
        /// </summary>
        private void FormLoad(object sender, EventArgs e)
        {
            AppHelper.LoadSettings(this);
        }

        /// <summary>
        /// save settings when ok button is clicked
        /// </summary>
        private void OKButtonClick(object sender, EventArgs e)
        {
            AppHelper.SaveSettings(this);
        }

        /// <summary>
        /// fire when the view button is clicked, to show the folder browser dialog and select a directory
        /// </summary>
        private void ViewButtonClick(object sender, EventArgs e)
        {
            using (FolderBrowserDialog f = new FolderBrowserDialog())
            {
                f.Description = Properties.Resources.SelectOutDescription;
                f.ShowNewFolderButton = true;
                bool exist = System.IO.Directory.Exists(Properties.Settings.Default.OutputDirectory);
                if (exist) f.SelectedPath = Properties.Settings.Default.OutputDirectory;
                DialogResult r = f.ShowDialog();
                if (r == DialogResult.OK) TBDirectory.Text = f.SelectedPath;
            }
        }

        /// <summary>
        /// fire when renameing parameters are changed
        /// </summary>
        private void ChangePreviewName(object sender, EventArgs e)
        {
            PreviewLabel.Text = GetPreviewName();
        }

        /// <summary>
        /// fire when the value of resize percentage track bar is changed
        /// </summary>
        private void OnResizePercChanged(object sender, EventArgs e)
        {
            LPercentage.Text = TBPercentageAdjust.Value.ToString() + "%";
        }

        /// <summary>
        /// fire when the value of compress percentage track bar is changed
        /// </summary>
        private void OnCompressPercChanged(object sender, EventArgs e)
        {
            LCompressPerc.Text = TBCompressPencentage.Value.ToString() + "%";
        }

        /// <summary>
        /// get preview name according to renaming parameters
        /// </summary>
        private string GetPreviewName()
        {
            return string.Format("{0}{1}{2}.ext", 
                TxPrefix.Text, Convert.ToInt32(SpinSeed.Value).ToString("D" + SpinDigit.Value), TxSuffix.Text);
        }
    }
}